using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for FormControl.
	/// </summary>
	public class FormControl : System.Windows.Forms.UserControl
	{
    private FreeFlow.WinFormsControls.FormControl clientFormControl;
    private System.Windows.Forms.Panel panel1;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.TextBox whenUserLoadFormLabel;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.TextBox whenUserSavesFormLabel;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.TextBox nameLabel;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.TextBox restrictViewingToLabel;
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FormControl()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      this.clientFormControl = new FreeFlow.WinFormsControls.FormControl();
      this.panel1 = new System.Windows.Forms.Panel();
      this.restrictViewingToLabel = new System.Windows.Forms.TextBox();
      this.label4 = new System.Windows.Forms.Label();
      this.nameLabel = new System.Windows.Forms.TextBox();
      this.label3 = new System.Windows.Forms.Label();
      this.whenUserSavesFormLabel = new System.Windows.Forms.TextBox();
      this.label2 = new System.Windows.Forms.Label();
      this.whenUserLoadFormLabel = new System.Windows.Forms.TextBox();
      this.label1 = new System.Windows.Forms.Label();
      this.panel1.SuspendLayout();
      this.SuspendLayout();
      // 
      // clientFormControl
      // 
      this.clientFormControl.AutoScroll = true;
      this.clientFormControl.Dock = System.Windows.Forms.DockStyle.Fill;
      this.clientFormControl.Location = new System.Drawing.Point(0, 224);
      this.clientFormControl.Name = "clientFormControl";
      this.clientFormControl.Size = new System.Drawing.Size(800, 232);
      this.clientFormControl.TabIndex = 0;
      // 
      // panel1
      // 
      this.panel1.Controls.Add(this.restrictViewingToLabel);
      this.panel1.Controls.Add(this.label4);
      this.panel1.Controls.Add(this.nameLabel);
      this.panel1.Controls.Add(this.label3);
      this.panel1.Controls.Add(this.whenUserSavesFormLabel);
      this.panel1.Controls.Add(this.label2);
      this.panel1.Controls.Add(this.whenUserLoadFormLabel);
      this.panel1.Controls.Add(this.label1);
      this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
      this.panel1.Location = new System.Drawing.Point(0, 0);
      this.panel1.Name = "panel1";
      this.panel1.Size = new System.Drawing.Size(800, 224);
      this.panel1.TabIndex = 1;
      // 
      // restrictViewingToLabel
      // 
      this.restrictViewingToLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
      this.restrictViewingToLabel.Location = new System.Drawing.Point(128, 160);
      this.restrictViewingToLabel.Multiline = true;
      this.restrictViewingToLabel.Name = "restrictViewingToLabel";
      this.restrictViewingToLabel.ReadOnly = true;
      this.restrictViewingToLabel.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
      this.restrictViewingToLabel.Size = new System.Drawing.Size(664, 56);
      this.restrictViewingToLabel.TabIndex = 7;
      this.restrictViewingToLabel.Text = "restrictViewingToLabel";
      // 
      // label4
      // 
      this.label4.Location = new System.Drawing.Point(8, 160);
      this.label4.Name = "label4";
      this.label4.Size = new System.Drawing.Size(100, 16);
      this.label4.TabIndex = 6;
      this.label4.Text = "Restrict viewing to:";
      // 
      // nameLabel
      // 
      this.nameLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
      this.nameLabel.BorderStyle = System.Windows.Forms.BorderStyle.None;
      this.nameLabel.Location = new System.Drawing.Point(128, 8);
      this.nameLabel.Name = "nameLabel";
      this.nameLabel.ReadOnly = true;
      this.nameLabel.Size = new System.Drawing.Size(664, 13);
      this.nameLabel.TabIndex = 5;
      this.nameLabel.Text = "nameLabel";
      // 
      // label3
      // 
      this.label3.Location = new System.Drawing.Point(8, 8);
      this.label3.Name = "label3";
      this.label3.Size = new System.Drawing.Size(100, 16);
      this.label3.TabIndex = 4;
      this.label3.Text = "Name:";
      // 
      // whenUserSavesFormLabel
      // 
      this.whenUserSavesFormLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
      this.whenUserSavesFormLabel.Location = new System.Drawing.Point(128, 96);
      this.whenUserSavesFormLabel.Multiline = true;
      this.whenUserSavesFormLabel.Name = "whenUserSavesFormLabel";
      this.whenUserSavesFormLabel.ReadOnly = true;
      this.whenUserSavesFormLabel.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
      this.whenUserSavesFormLabel.Size = new System.Drawing.Size(664, 56);
      this.whenUserSavesFormLabel.TabIndex = 3;
      this.whenUserSavesFormLabel.Text = "whenUserSavesFormLabel";
      // 
      // label2
      // 
      this.label2.Location = new System.Drawing.Point(8, 96);
      this.label2.Name = "label2";
      this.label2.Size = new System.Drawing.Size(120, 16);
      this.label2.TabIndex = 2;
      this.label2.Text = "When user saves form:";
      // 
      // whenUserLoadFormLabel
      // 
      this.whenUserLoadFormLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
      this.whenUserLoadFormLabel.Location = new System.Drawing.Point(128, 32);
      this.whenUserLoadFormLabel.Multiline = true;
      this.whenUserLoadFormLabel.Name = "whenUserLoadFormLabel";
      this.whenUserLoadFormLabel.ReadOnly = true;
      this.whenUserLoadFormLabel.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
      this.whenUserLoadFormLabel.Size = new System.Drawing.Size(664, 56);
      this.whenUserLoadFormLabel.TabIndex = 1;
      this.whenUserLoadFormLabel.Text = "whenUserLoadFormLabel";
      // 
      // label1
      // 
      this.label1.Location = new System.Drawing.Point(8, 32);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(120, 16);
      this.label1.TabIndex = 0;
      this.label1.Text = "When user loads form:";
      // 
      // FormControl
      // 
      this.Controls.Add(this.clientFormControl);
      this.Controls.Add(this.panel1);
      this.Name = "FormControl";
      this.Size = new System.Drawing.Size(800, 456);
      this.panel1.ResumeLayout(false);
      this.ResumeLayout(false);

    }
		#endregion

    public void LoadForm(FreeFlow.Administration.Form form)
    {
      if (form.FormLayout != null)
      {
        FreeFlow.Client.Form clientForm = new FreeFlow.Client.Form(form.FormLayout.DocumentElement, form.Server);
        clientFormControl.Populate(clientForm);
        clientFormControl.MakeFieldsReadOnly();
      }
      nameLabel.Text = form.Name;
      whenUserLoadFormLabel.Text = form.WhenUserLoadsForm;
      whenUserSavesFormLabel.Text = form.WhenUserSavesForm;
      restrictViewingToLabel.Text = form.RestrictViewingTo;
    }

    public Size PreferredControlSize
    {
      get
      {
        return clientFormControl.PreferredSize;
      }
    }
  }
}
